package com.ruoyi.web.controller.unit;

import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.Pictures;
import com.deepoove.poi.data.Rows;
import com.deepoove.poi.data.Tables;
import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.mapper.*;

import com.ruoyi.system.service.IRotordataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * @Auther lql
 * @Date 2024/8/11
 */

@Service
public class LsyDownLoad {
    @Resource
    private tupian tpian;
    @Autowired
    private InspectheaderMapper headerMapper;
    @Autowired
    private UltrasonicdataMapper ultrasonicdataMapper;

    @Autowired
    private NonrotordataMapper nonrotordataMapper;
    @Autowired
    private IRotordataService rotordataService;

    @Autowired
    private RotordataMapper rotordataMapper;
    @Autowired
    private DepthometerdataMapper depthometerdataMapper;

    public DownLoadVo getDownLoadVo(Task task) {
        DownLoadVo vo = new DownLoadVo();
        List<Nonrotordata> nonrotordatas = new ArrayList<>();
        HashMap<String, Object> data = new HashMap<>();
        data.put("task", task);
        String taskId=task.getTaskid();
        Integer len=taskId.length();
        String taskNum=taskId.substring(len - 4);
        data.put("taskNum", taskNum);
        //XIUGAI 2024-11-08 09:46:59 calibedTime
        Inspectheader inspectheader = headerMapper.selectInspectheaderByID(task.getTaskid());

        Inspectheader inspec = headerMapper.electricwavedataBydate(task.getCalibedTime().substring(0,10));
        data.put("ins", inspec);
        String calibedTime = task.getCalibedTime();
        // 截取字符串 年月日
        String year = null;
        String month = null;
        String day = null;
        if (calibedTime != null) {
            year = calibedTime.substring(0, 4);
            month = calibedTime.substring(5, 7);
            day = calibedTime.substring(8, 10);
        }
        data.put("year", year);
        data.put("month", month);
        data.put("day", day);
        if ("转子式流速仪".equals(task.getDevicemodel())) {
            BigDecimal maxV = rotordataMapper.selectMaxv(task.getTaskid());
            BigDecimal miniV = rotordataMapper.selectMiniv(task.getTaskid());
            BigDecimal startv = rotordataMapper.selectStartv(task.getTaskid());
            data.put("vmax", maxV);
            data.put("vmini", miniV);
            data.put("startv", startv);
            Rotordata rotordata = new Rotordata();
            rotordata.setTaskid(task.getTaskid());
            // 插入一个含有样式的表格
            Tables.TableBuilder tabData = Tables
                    // 创建一个指定宽度的表格（docx 文档的 80% 宽度）
                    .ofPercentWidth("100%")
                    // 表格设为水平居中
                    .center();
            tabData.addRow(Rows.of("序号", "实际车速(m/s)", "转率n（r/s）", "计算速度(m/s)", "绝对误差（m/s）", "相对误差（%）")
                    // 设置文字颜色
                    .textColor("000000")
                    // 设置对应表格的背景颜色

                    // 文字居中
                    .center()
                    .create()
            );


            BigDecimal v1 = new BigDecimal("0");
            BigDecimal v2 = new BigDecimal("0");
            BigDecimal v3 = new BigDecimal("0");
            BigDecimal v4 = new BigDecimal("0");
            Integer a1=0;
            Integer a2=0;
            Integer a3=0;
            Integer a4=0;
            List<BigDecimal> xValues = new ArrayList<>();
            List<BigDecimal> yValues = new ArrayList<>();
            //流速检测记录表
            List<Rotordata> rotordataList = rotordataService.selectRotordataList(rotordata);
            if (rotordataList.size() > 0) {
                for (int i = 0; i < rotordataList.size(); i++) {
                    //将速度值放入数组
                    xValues.add(rotordataList.get(i).getSetspeed());
                    yValues.add(rotordataList.get(i).getTurnspeed());
                    //流速仪实际速度为 a+b*n
                    BigDecimal avalue = inspectheader.getAValue().setScale(3, RoundingMode.HALF_UP);
                    BigDecimal bvalue = inspectheader.getBValue().setScale(3, RoundingMode.HALF_UP);
                    BigDecimal lsv=avalue.add(bvalue.multiply(rotordataList.get(i).getTurnspeed()));
                    lsv=lsv.setScale(4, RoundingMode.HALF_UP);
                    //" @Excel(name = "绝对 ")
                    //    private BigDecimal absolute;
                    //    @Excel(name = "相对")
                    //    private BigDecimal relative;
                    BigDecimal absolute =new BigDecimal(0.00);
                    BigDecimal relative = new BigDecimal(0.00);
                    absolute = lsv.subtract(rotordataList.get(i).getRealspeed()).abs();
                    relative = absolute.multiply(new BigDecimal(100)).divide(rotordataList.get(i).getRealspeed(), 2, RoundingMode.HALF_UP);

                    absolute=absolute.setScale(4, RoundingMode.HALF_UP);

                    BigDecimal s = rotordataList.get(i).getRealspeed();
                    if (s.compareTo(new BigDecimal("0.030")) >= 0 && s.compareTo(new BigDecimal("0.5")) < 0) {
                        a1=a1+1;
                        v1=v1.add(relative.abs());
                    }
                    if (s.compareTo(new BigDecimal("0.5")) > 0 && s.compareTo(new BigDecimal("1.5")) <= 0) {
                        a2=a2+1;
                        v2=v2.add(relative.abs());
                    }
                    if (s.compareTo(new BigDecimal("1.5")) > 0 && s.compareTo(new BigDecimal("3.5")) <= 0) {
                        a3=a3+1;
                        v3=v3.add(relative.abs());
                    }
                    if (s.compareTo(new BigDecimal("3.5")) > 0) {
                        a4=a4+1;
                        v4=v4.add(relative.abs());
                    }

                    if (1L==rotordataList.get(i).getFitting()){

                        absolute = lsv.subtract(rotordataList.get(i).getRealspeed()).abs();
                        relative = absolute.multiply(new BigDecimal(100)).divide(rotordataList.get(i).getRealspeed(), 2, RoundingMode.HALF_UP);

                        absolute=absolute.setScale(4, RoundingMode.HALF_UP);


                    }

                    int a = i + 1;
                    // 输出结果
                    String absolute1="";
                    if (absolute.equals(new BigDecimal(0))){
                        absolute1="-";
                    }else {
                        absolute1=absolute.toString();
                    }
                    String relative1="";
                    BigDecimal setspeed=rotordataList.get(i).getSetspeed();
                   BigDecimal X= new BigDecimal(0.030).setScale(3, RoundingMode.HALF_UP);
                    if (setspeed.compareTo(X) <= 0) {
                        relative1 = "-";
                    } if(setspeed.compareTo(X) == 0){
                        relative1 = "-";
                    }
                    else {
                        relative1=relative.toString(); // 或者其他默认值
                    }
                    if(1L!=rotordataList.get(i).getFitting()){
                        relative1 = "-";
                    }

                    BigDecimal Realspeed=rotordataList.get(i).getRealspeed().setScale(4, RoundingMode.HALF_UP);
                    rotordataList.get(i).setRealspeed(Realspeed);
                    BigDecimal turnspeed=rotordataList.get(i).getTurnspeed().setScale(4, RoundingMode.HALF_UP);
                    rotordataList.get(i).setTurnspeed(turnspeed);

                    tabData.addRow(Rows.of(a + "", rotordataList.get(i).getRealspeed().toString(), rotordataList.get(i).getTurnspeed().toString(), lsv.toString(), absolute1, relative1) // 文字居中
                            .center().create());
                }
                //速度级分段误差检测记录表
                if(1!=0){
                    v1 = v1.divide(BigDecimal.valueOf(a1), 2, RoundingMode.HALF_UP);
                }else{
                   v1 = new BigDecimal("0");

                }
                if(a2!=0){
                    v2 = v2.divide(BigDecimal.valueOf(a2), 2, RoundingMode.HALF_UP);
                }else{
                    v2 = new BigDecimal("0");

                }
                if(a3!=0){
                    v3 = v3.divide(BigDecimal.valueOf(a3), 2, RoundingMode.HALF_UP);
                }else{
                    v3 = new BigDecimal("0");

                }
                if(a4!=0){
                    v4 = v4.divide(BigDecimal.valueOf(a4), 2, RoundingMode.HALF_UP);
                }else{
                     v4 = new BigDecimal("0");
                }


                data.put("v1", v1+"%");
                data.put("v2", v2+"%");
                data.put("v3", v3+"%");
                data.put("v4", v4+"%");
                tpian.upLoadPng(rotordataList, task);
            }
            LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
            Configure configure = Configure.builder().bind("table1", policy).bind("table2", policy).build();
            data.put("table1", rotordataList);

            data.put("table", tabData.create());
            data.put("img", Pictures.ofLocal("D:\\hbsw\\" + task.getTaskid() + ".jpg").size(500, 700).create());
            if (inspectheader != null) {
                BigDecimal a = inspectheader.getAValue().setScale(3, RoundingMode.HALF_UP);
                BigDecimal b = inspectheader.getBValue().setScale(3, RoundingMode.HALF_UP);
                BigDecimal multipliedValue = inspectheader.getMValue().multiply(BigDecimal.valueOf(100));
                BigDecimal m = multipliedValue.setScale(2, RoundingMode.HALF_UP);
                data.put("a", a);
                data.put("b", b);
                data.put("m", m);

            }

            //将数据存入折线图生成方法
            vo.setConfigure(configure);
            //再将图片插入word文档
            vo.setData(data);
            vo.setUrl("D:\\hbsw\\liusuyi.docx");

        } else if ("电波流速仪".equals(task.getDevicemodel()) || "超声波流速仪".equals(task.getDevicemodel())|| "直读式转子流速仪".equals(task.getDevicemodel())) {
            int f = 0;
            nonrotordatas = nonrotordataMapper.selectNonrotordataByTaskId(task.getTaskid());
            if(nonrotordatas.size()>0){
                Nonrotordata nodata = nonrotordatas.get(8);
                String[] split = nodata.getStrIV().split(" ");
                BigDecimal absolute=new BigDecimal("0");
                //pingjunzi
                BigDecimal avg=new BigDecimal("0");
                BigDecimal relative=new BigDecimal("0");
                for (String s:split){
                    avg=avg.add(new BigDecimal(s));
                }
                avg=avg.divide(new BigDecimal(split.length),2,RoundingMode.HALF_UP);
                nodata.setAverageIV(avg);
                absolute=avg.subtract(nodata.getSetspeed());
                nodata.setAbsolute(absolute);
                //百分比
                absolute=absolute.multiply(new BigDecimal("100"));

                relative=absolute.divide(nodata.getSetspeed(),2,RoundingMode.HALF_UP);
                nodata.setRelative(relative);
                nodata.setAverageIV(nodata.getAverageIV().setScale(2, RoundingMode.HALF_UP));
                nodata.setRelative((nodata.getRelative().setScale(2, RoundingMode.HALF_UP)));
                data.put("nodata", nodata);
            }

            for (Nonrotordata nonrotordata : nonrotordatas) {
                f = f + 1;
                nonrotordata.setNumber(f);
                //将StrIV根据空格截取截取后依次赋值给Nonrotordata中的IV1到IV10
                String[] split = nonrotordata.getStrIV().split(" ");

                if (split.length >= 10) {

                    nonrotordata.setIV1(new BigDecimal(split[0]));
                    nonrotordata.setIV2(new BigDecimal(split[1]));
                    nonrotordata.setIV3(new BigDecimal(split[2]));
                    nonrotordata.setIV4(new BigDecimal(split[3]));
                    nonrotordata.setIV5(new BigDecimal(split[4]));
                    nonrotordata.setIV6(new BigDecimal(split[5]));
                    nonrotordata.setIV7(new BigDecimal(split[6]));
                    nonrotordata.setIV8(new BigDecimal(split[7]));
                    nonrotordata.setIV9(new BigDecimal(split[8]));
                    nonrotordata.setIV10(new BigDecimal(split[9]));


                }
                if (split.length == 9) {
                    nonrotordata.setIV1(new BigDecimal(split[0]));
                    nonrotordata.setIV2(new BigDecimal(split[1]));
                    nonrotordata.setIV3(new BigDecimal(split[2]));
                    nonrotordata.setIV4(new BigDecimal(split[3]));
                    nonrotordata.setIV5(new BigDecimal(split[4]));
                    nonrotordata.setIV6(new BigDecimal(split[5]));
                    nonrotordata.setIV7(new BigDecimal(split[6]));
                    nonrotordata.setIV8(new BigDecimal(split[7]));
                    nonrotordata.setIV9(new BigDecimal(split[8]));
                }
                if (split.length == 8) {
                    nonrotordata.setIV1(new BigDecimal(split[0]));
                    nonrotordata.setIV2(new BigDecimal(split[1]));
                    nonrotordata.setIV3(new BigDecimal(split[2]));
                    nonrotordata.setIV4(new BigDecimal(split[3]));
                    nonrotordata.setIV5(new BigDecimal(split[4]));
                    nonrotordata.setIV6(new BigDecimal(split[5]));
                    nonrotordata.setIV7(new BigDecimal(split[6]));
                    nonrotordata.setIV8(new BigDecimal(split[7]));
                }
                if (split.length == 7) {
                    nonrotordata.setIV1(new BigDecimal(split[0]));
                    nonrotordata.setIV2(new BigDecimal(split[1]));
                    nonrotordata.setIV3(new BigDecimal(split[2]));
                    nonrotordata.setIV4(new BigDecimal(split[3]));
                    nonrotordata.setIV5(new BigDecimal(split[4]));
                    nonrotordata.setIV6(new BigDecimal(split[5]));
                    nonrotordata.setIV7(new BigDecimal(split[6]));

                }
                if (split.length == 6) {
                    nonrotordata.setIV1(new BigDecimal(split[0]));
                    nonrotordata.setIV2(new BigDecimal(split[1]));
                    nonrotordata.setIV3(new BigDecimal(split[2]));
                    nonrotordata.setIV4(new BigDecimal(split[3]));
                    nonrotordata.setIV5(new BigDecimal(split[4]));
                    nonrotordata.setIV6(new BigDecimal(split[5]));
                }
                if (split.length == 5) {
                    nonrotordata.setIV1(new BigDecimal(split[0]));
                    nonrotordata.setIV2(new BigDecimal(split[1]));
                    nonrotordata.setIV3(new BigDecimal(split[2]));
                    nonrotordata.setIV4(new BigDecimal(split[3]));
                    nonrotordata.setIV5(new BigDecimal(split[4]));

                }
                if (split.length == 4) {
                    nonrotordata.setIV1(new BigDecimal(split[0]));
                    nonrotordata.setIV2(new BigDecimal(split[1]));
                    nonrotordata.setIV3(new BigDecimal(split[2]));
                    nonrotordata.setIV4(new BigDecimal(split[3]));
                }
                if (split.length == 3) {
                    nonrotordata.setIV1(new BigDecimal(split[0]));
                    nonrotordata.setIV2(new BigDecimal(split[1]));
                    nonrotordata.setIV3(new BigDecimal(split[2]));
                }
                if (split.length == 2) {
                    nonrotordata.setIV1(new BigDecimal(split[0]));
                    nonrotordata.setIV2(new BigDecimal(split[1]));

                }
                if (split.length == 1) {
                    nonrotordata.setIV1(new BigDecimal(split[0]));
                }
                if(null!=nonrotordata.getIV1()){
                    nonrotordata.setIV1(nonrotordata.getIV1().setScale(2, RoundingMode.HALF_UP));
                }
                if(null!=nonrotordata.getIV2()){
                    nonrotordata.setIV2(nonrotordata.getIV2().setScale(2, RoundingMode.HALF_UP));
                }
                if(null!=nonrotordata.getIV3()){
                    nonrotordata.setIV3(nonrotordata.getIV3().setScale(2, RoundingMode.HALF_UP));
                }
                if(null!=nonrotordata.getIV4()){
                    nonrotordata.setIV4(nonrotordata.getIV4().setScale(2, RoundingMode.HALF_UP));
                }
                if(null!=nonrotordata.getIV5()){
                    nonrotordata.setIV5(nonrotordata.getIV5().setScale(2, RoundingMode.HALF_UP));
                }
                if(null!=nonrotordata.getIV6()){
                    nonrotordata.setIV6(nonrotordata.getIV6().setScale(2, RoundingMode.HALF_UP));
                }
                if(null!=nonrotordata.getIV7()){
                    nonrotordata.setIV7(nonrotordata.getIV7().setScale(2, RoundingMode.HALF_UP));
                }
                if(null!=nonrotordata.getIV8()){
                    nonrotordata.setIV8(nonrotordata.getIV8().setScale(2, RoundingMode.HALF_UP));
                }
                if(null!=nonrotordata.getIV9()){
                    nonrotordata.setIV9(nonrotordata.getIV9().setScale(2, RoundingMode.HALF_UP));
                }
                if(null!=nonrotordata.getIV10()){
                    nonrotordata.setIV10(nonrotordata.getIV10().setScale(2, RoundingMode.HALF_UP));}

                nonrotordata.setSetspeed(nonrotordata.getSetspeed().setScale(3, RoundingMode.HALF_UP));

                BigDecimal absolute=new BigDecimal("0");
                //pingjunzi
                BigDecimal avg=new BigDecimal("0");
                BigDecimal relative=new BigDecimal("0");
                for (String s:split){
                    avg=avg.add(new BigDecimal(s));
                }
                avg=avg.divide(new BigDecimal(split.length),3,RoundingMode.HALF_UP);
                nonrotordata.setAverageIV(avg);
                absolute=avg.subtract(nonrotordata.getSetspeed());
                nonrotordata.setAbsolute(absolute);
                //百分比
                absolute=absolute.multiply(new BigDecimal("100"));

                relative=absolute.divide(nonrotordata.getSetspeed(),2,RoundingMode.HALF_UP);
                nonrotordata.setRelative(relative);

                if(nonrotordata.getSetspeed().compareTo(new BigDecimal(0.5))<=0){
                    nonrotordata.setRelative(null);
                }
            }

            vo.setUrl("D:\\hbsw\\csblsy.docx");

        } else if ("海流计".equals(task.getDevicemodel()) || "流速流向仪".equals(task.getDevicemodel())) {
            int f = 0;
            nonrotordatas = nonrotordataMapper.selectNonrotordataByTaskId(task.getTaskid());

            Ultrasonicdata ultrasonicdata = new Ultrasonicdata();
            ultrasonicdata.setTaskid(task.getTaskid());


            List<Ultrasonicdata> ultrasonicdataList = ultrasonicdataMapper.selectUltrasonicdataList(ultrasonicdata);
            int uu=0;
            for (Ultrasonicdata u : ultrasonicdataList) {
                String originalString = u.getValue();
                String replacedString = originalString.replaceAll("\\s+", " ");
                String[] split = replacedString.split(" ");
                u.setAvalue(new BigDecimal(split[0]).setScale(1, RoundingMode.HALF_UP));
                u.setBvalue(new BigDecimal(split[1]).setScale(1, RoundingMode.HALF_UP));
                u.setAverage((u.getAvalue().add(u.getBvalue())).divide(new BigDecimal(2.0),1,RoundingMode.HALF_UP));
                u.setStroke(u.getAvalue().subtract(u.getBvalue()).setScale(1, RoundingMode.HALF_UP));
                u.setViewStroke( u.getAngle().subtract(u.getAverage()).setScale(1, RoundingMode.HALF_UP));
                u.setAngle(u.getAngle().setScale(0, RoundingMode.HALF_UP));
                uu=uu+1;
                data.put("ultra"+uu, u);
            }
            if(nonrotordatas.size()>0){
               Nonrotordata nonr= nonrotordatas.get(0);
                String[] split = nonr.getStrIV().split(" ");
                if (split.length >= 5) {
                    nonr.setIV1(new BigDecimal(split[0]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIV2(new BigDecimal(split[1]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIV3(new BigDecimal(split[2]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIV4(new BigDecimal(split[3]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIV5(new BigDecimal(split[4]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIVD1(nonr.getIV1().subtract(nonr.getSetspeed()));
                    nonr.setIVD2(nonr.getIV2().subtract(nonr.getSetspeed()));
                    nonr.setIVD3(nonr.getIV3().subtract(nonr.getSetspeed()));
                    nonr.setIVD4(nonr.getIV4().subtract(nonr.getSetspeed()));
                    nonr.setIVD5(nonr.getIV5().subtract(nonr.getSetspeed()));
                }
                if (split.length == 4) {
                    nonr.setIV1(new BigDecimal(split[0]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIV2(new BigDecimal(split[1]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIV3(new BigDecimal(split[2]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIV4(new BigDecimal(split[3]).setScale(2, RoundingMode.HALF_UP));

                    nonr.setIVD1(nonr.getIV1().subtract(nonr.getSetspeed()));
                    nonr.setIVD2(nonr.getIV2().subtract(nonr.getSetspeed()));
                    nonr.setIVD3(nonr.getIV3().subtract(nonr.getSetspeed()));
                    nonr.setIVD4(nonr.getIV4().subtract(nonr.getSetspeed()));

                }
                if (split.length == 3) {
                    nonr.setIV1(new BigDecimal(split[0]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIV2(new BigDecimal(split[1]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIV3(new BigDecimal(split[2]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIVD1(nonr.getIV1().subtract(nonr.getSetspeed()));
                    nonr.setIVD2(nonr.getIV2().subtract(nonr.getSetspeed()));
                    nonr.setIVD3(nonr.getIV3().subtract(nonr.getSetspeed()));
                }
                if (split.length == 2) {
                    nonr.setIV1(new BigDecimal(split[0]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIV2(new BigDecimal(split[1]).setScale(2, RoundingMode.HALF_UP));

                    nonr.setIVD1(nonr.getIV1().subtract(nonr.getSetspeed()));
                    nonr.setIVD2(nonr.getIV2().subtract(nonr.getSetspeed()));

                }

                if (split.length == 1) {
                    nonr.setIV1(new BigDecimal(split[0]).setScale(2, RoundingMode.HALF_UP));
                    nonr.setIVD1(nonr.getIV1().subtract(nonr.getSetspeed()));
                }
                BigDecimal Setspeed=nonr.getSetspeed().setScale(3, RoundingMode.HALF_UP);
                nonr.setSetspeed(Setspeed);
                data.put("nonr", nonr);
            }
            for (Nonrotordata nonrotordata : nonrotordatas) {
                f = f + 1;
                nonrotordata.setNumber(f);
                nonrotordata.setAbsolute(nonrotordata.getSetspeed().subtract(nonrotordata.getAverageIV()).setScale(2, RoundingMode.HALF_UP));
                BigDecimal averageIV= nonrotordata.getAverageIV().setScale(2, RoundingMode.HALF_UP);
                nonrotordata.setAverageIV(averageIV);
                //将StrIV根据空格截取截取后依次赋值给Nonrotordata中的IV1到IV10
                String[] split = nonrotordata.getStrIV().split(" ");
                if (split.length == 5) {
                    nonrotordata.setIV1(new BigDecimal(split[0]).setScale(2, RoundingMode.HALF_UP));
                    nonrotordata.setIV2(new BigDecimal(split[1]).setScale(2, RoundingMode.HALF_UP));
                    nonrotordata.setIV3(new BigDecimal(split[2]).setScale(2, RoundingMode.HALF_UP));
                    nonrotordata.setIV4(new BigDecimal(split[3]).setScale(2, RoundingMode.HALF_UP));
                    nonrotordata.setIV5(new BigDecimal(split[4]).setScale(2, RoundingMode.HALF_UP));

                }
                if (split.length == 4) {
                    nonrotordata.setIV1(new BigDecimal(split[0]).setScale(2, RoundingMode.HALF_UP));
                    nonrotordata.setIV2(new BigDecimal(split[1]).setScale(2, RoundingMode.HALF_UP));
                    nonrotordata.setIV3(new BigDecimal(split[2]).setScale(2, RoundingMode.HALF_UP));
                    nonrotordata.setIV4(new BigDecimal(split[3]).setScale(2, RoundingMode.HALF_UP));
                }
                if (split.length == 3) {
                    nonrotordata.setIV1(new BigDecimal(split[0]).setScale(2, RoundingMode.HALF_UP));
                    nonrotordata.setIV2(new BigDecimal(split[1]).setScale(2, RoundingMode.HALF_UP));
                    nonrotordata.setIV3(new BigDecimal(split[2]).setScale(2, RoundingMode.HALF_UP));
                }
                if (split.length == 2) {
                    nonrotordata.setIV1(new BigDecimal(split[0]).setScale(2, RoundingMode.HALF_UP));
                    nonrotordata.setIV2(new BigDecimal(split[1]).setScale(2, RoundingMode.HALF_UP));

                }
                if (split.length == 1) {
                    nonrotordata.setIV1(new BigDecimal(split[0]).setScale(2, RoundingMode.HALF_UP));
                }


            }

            vo.setUrl("D:\\hbsw\\lslxy.docx");


        } else if ("测深仪".equals(task.getDevicemodel())) {
            Tables.TableBuilder tabData = Tables
                    // 创建一个指定宽度的表格（docx 文档的 80% 宽度）
                    .ofPercentWidth("100%")
                    // 表格设为水平居中
                    .center();

            tabData.addRow(Rows.of("序号", "仪器宣称盲区（m）", "标准水深（m）", "测量水深（m）")
                    // 设置文字颜色
                    .textColor("000000")
                    // 设置对应表格的背景颜色

                    // 文字居中
                    .center()
                    .create()
            );
            List<Depthometerdata> MDepthometerdata = depthometerdataMapper.selectMqList(task.getTaskid());
            if (MDepthometerdata.size() > 0) {
                for (int i = 0; i < MDepthometerdata.size(); i++) {
                    Depthometerdata depthometerdata = (Depthometerdata) MDepthometerdata.get(i);
                    tabData.addRow(Rows.of(i + 1 + "", depthometerdata.getBlindArea().toString(), depthometerdata.getSettingDist().toString(), depthometerdata.getCircledist1().toString()). center().create());
                }
            }
            data.put("mq", tabData.create());
            vo.setUrl("D:\\hbsw\\csy.docx");
        }
        LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
        // 将bz设置为行循环绑定的数据源的key,即key是bz的value会在模板中的{{bz}}处进行解析
        Configure configure = Configure.builder().bind("table1", policy).bind("table2", policy).bind("table3", policy).build();
        List<Depthometerdata> forms = new ArrayList<>();
        List<Depthometerdata> depdata = depthometerdataMapper.selectClwcList(task.getTaskid());
        int j = 0;
        for (Depthometerdata d : depdata) {
            j = j + 1;
            d.setNumber(j);
            if(null!=d.getSettingDist()){
                d.setSettingDist(d.getSettingDist().setScale(2, RoundingMode.HALF_UP));
            }
            if(null!=d.getCircledist1()){
                d.setCircledist1(d.getCircledist1().setScale(2, RoundingMode.HALF_UP));
            }
            if(null!=d.getCircledist2()){
                d.setCircledist2(d.getCircledist2().setScale(2, RoundingMode.HALF_UP));
            }
            if(null!=d.getCircledist3()){
                d.setCircledist3(d.getCircledist3().setScale(2, RoundingMode.HALF_UP));
            }
            if(null!=d.getCircledist4()){
                d.setCircledist4(d.getCircledist4().setScale(2, RoundingMode.HALF_UP));
            }
            if(null!=d.getCircledist5()){
                d.setCircledist5(d.getCircledist5().setScale(2, RoundingMode.HALF_UP));
            }
            if(null!=d.getAbsolute()){
                d.setAbsolute(d.getAbsolute().setScale(2, RoundingMode.HALF_UP));
            }
            if(null!=d.getAvger()){
                d.setAvger(d.getAvger().setScale(2, RoundingMode.HALF_UP));
            }
            if(null!=d.getRelative()){
                d.setRelative(d.getRelative().setScale(2, RoundingMode.HALF_UP));
            }
            if (new BigDecimal(5).compareTo(d.getSettingDist())==1||new BigDecimal(5).compareTo(d.getSettingDist())==0){
                d.setAbsolute2("-");
            }else{
                d.setAbsolute2(d.getAbsolute()+"%");
            }
            forms.add(d);
        }
        data.put("table1", forms);

        data.put("table3", nonrotordatas);

        vo.setData(data);
        vo.setConfigure(configure);

        return vo;

    }
}
